//获取该用户所有文件数据
import { message } from 'antd';
import { GetApi } from '../api/request'
import { setLocalStorage, clearAllLocalStorage } from './utils'

//获取该用户的所有文件信息并保存到本地缓存中
export async function getAllFileData(account) {
    let res = await GetApi('/filedata', { account })
    if (res.data.code === 205) {
        message.destroy();
        message.warning({ content: res.data.msg, duration: 3 });
        clearAllLocalStorage()
        this.props.history.push('/login')
    } else {
        if (res.data.code === 200) {
            let { data } = res.data
            let oneDay = (new Date()).getTime() - 30 * 6000
            let fileList = data.filter((v) => {
                let fileList = {}
                if (parseInt(v.upload_date) > oneDay) {
                    fileList.key = v.id
                    fileList.name = v.name
                    fileList.size = v.size
                }
                return fileList
            })
            setLocalStorage('fileList', JSON.stringify(fileList))
            setLocalStorage('allFileData', JSON.stringify({ time: Date.now(), data }))
        }
    }

}


